package gov.ccswj.modules.job.task;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import gov.ccswj.common.utils.R;
import gov.ccswj.modules.bdbusiness.entity.TPageParamEntity;
import gov.ccswj.modules.bdbusiness.service.TPageParamService;
import gov.ccswj.modules.ccbusiness.entity.CChangeinfoEntity;
import gov.ccswj.modules.ccbusiness.entity.CCompanyNameEntity;
import gov.ccswj.modules.ccbusiness.integratedata.IntegrateDate;
import gov.ccswj.modules.ccbusiness.service.CChangeinfoService;
import gov.ccswj.modules.ccbusiness.service.CCompanyNameService;
import gov.ccswj.modules.job.utils.JsonUtils;

/**
 * 企业变更信息
 * 
 * @author ZhangYx
 * @email ********@gmail.com
 * @date 2017-10-31 11:46:26
 */
@Component("ChangeinfoTask")
public class ChangeinfoTask {

	@Autowired
	private CCompanyNameService cCompanyNameService;

	@Autowired
	private CChangeinfoService cChangeinfoService;
	@Autowired
	private TPageParamService tPageParamService;

	 public R runner(String obj){
		    
		 List<CCompanyNameEntity> allCName=new ArrayList<>();
		
		if(obj.equals("0")){
			TPageParamEntity pp=tPageParamService.quary(1);
			allCName = cCompanyNameService.getList(pp.getPagenum(),pp.getLimitnum());
		}else{
			CCompanyNameEntity cname=new CCompanyNameEntity();
			cname.setName(obj.toString());
			allCName.add(cname);
		}
		for (CCompanyNameEntity cCompanyNameEntity : allCName) {
			String resultdata = IntegrateDate.getCompanyData("getRegisterChangeInfo", cCompanyNameEntity.getName(), 0);
			List<Object> list = JsonUtils.getdate(resultdata, CChangeinfoEntity.class);
			for (Object c : list) {
				CChangeinfoEntity cm = new CChangeinfoEntity();
				cm = (CChangeinfoEntity) c;
				cm.setEntname(cCompanyNameEntity.getName());
				cChangeinfoService.deleteByname(cm.getEntname());
				cChangeinfoService.save(cm);
			}
		}
		return R.ok();
	}

}
